//
//  SetViewController.m
//  ios-test
//
//  Created by Apple -11 on 15/10/22.
//  Copyright (c) 2015年 Apple -11. All rights reserved.
//

#import "SetViewController.h"

@interface SetViewController ()

@end

@implementation SetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.setArray = [NSArray arrayWithObjects:@"清除缓存",@"2G/3G/4G",@"是否接受推送" ,nil];
    self.setArray2 = [NSArray arrayWithObjects:@"设置PIN密码管理",@"通用",@"关于",@"版本" ,nil];
    
    self.setView.tableFooterView=[[UIView alloc]init];
    //self.view.backgroundColor=[UIColor lightGrayColor];
    //self.setView.backgroundColor=[UIColor lightGrayColor];

    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)viewWillAppear:(BOOL)animated{
    [self.setView reloadData];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        return 3;
    }else
        return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    static NSString *cellStr = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
    }
    
    if (indexPath.section==0) {
        NSString *menu = (NSString *)[self.setArray objectAtIndex:indexPath.row];
        ;
        cell.textLabel.text = menu;
        
        if (indexPath.row==1) {
            switch1=[[UISwitch alloc]initWithFrame:CGRectMake(300, 10, 30, 20)];
            [cell addSubview:switch1];
        }else if (indexPath.row==2){
            switch2=[[UISwitch alloc]initWithFrame:CGRectMake(300, 10, 30, 20)];
            [cell addSubview:switch2];
        }
    }else{
        NSString *menu = (NSString *)[self.setArray2 objectAtIndex:indexPath.row];
        ;
        cell.textLabel.text = menu;

    }
    
        return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section==1 && indexPath.row==0) {
        ChoosePasswordViewController *choose=[[ChoosePasswordViewController alloc]init];
        [self presentViewController:choose animated:YES completion:nil];
    }
}

-(IBAction)back:(id)sender{
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
